#include "monoSample.h"

void monoSample(Scene& scene, Viewerf& viewer) {
    Vector3f& pos = viewer.pos;
    Vector3f& frontDir = viewer.dir;
    Vector3f rightDir = frontDir ^ Vector3f(0, 0, 1);
    Vector3f upDir = rightDir ^ frontDir;

    float scale = tan(viewer.fov * 0.5);

    glBegin(GL_POINTS);
        for (int i = 0; i < viewer.viewsizeY; i++) {
            float up = float(i) / viewer.viewsizeY - 0.5;
            Vector3f columnDir = frontDir + up * scale * upDir;

            for (int j = 0; j < viewer.viewsizeX; j++) {
                float right = float(j) / viewer.viewsizeX - 0.5;

                Vector3f dir = columnDir + right * scale * rightDir;

                dir.normalize();

                Color3f c = scene.traceRay(Ray(pos, dir));

                setPixel(j, i, c);
            }
        }
    glEnd();

    //printf("frame\n");
}
